package com.awcall.iot.controller;

import com.awcall.iot.common.BaseController;
import com.awcall.iot.common.ResponseResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author lzy
 * @date 2018/4/2
 */
@RestController
@RequestMapping("/admin/total")
public class TotalController extends BaseController {

    @RequestMapping("/index")
    public static ResponseResult index(String code) {

        String URL = "jdbc:mysql://211.154.194.46:3306/finace_total?characterEncoding=utf8&useSSL=false";
        String USER = "root";
        String PASSWORD = "shyx!qaz@wsx";
        String sql = "SELECT type FROM bd_fiance_total WHERE code = ?";
        String result = "";
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
            PreparedStatement pst = conn.prepareStatement(sql);
            pst.setString(1, code);
            ResultSet rs = pst.executeQuery();
            while (rs.next()) {
                result = rs.getString("type");
            }
            //关闭资源
            rs.close();
            pst.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new ResponseResult<>(result);
    }

    public static void main(String[] args) {
        ResponseResult index = index("132456");
        System.out.println(index.getData());
    }

}
